//---------------------------------------------------------------------------- // File: CBank.h // Class: CBank -- Class Bank // Type: Data Management // Author: Ken Anderson // Date: 5/14/04 // Updates: // 9/13/04 -- Updated to use the Exists member function the same as the index function. // The index function lacked the ability to notify the caller of failed elements // not found in the bank, so Exist was modified to return the index and the index // function was eliminated. // // NOTE: The CBank class deals with void pointers that can create memory leaks, // if the class calling it does not properly clean it's memory that it allocated // before placing it in the class. What goes in, must come out, and the CBank // does not have the ability to detect what void pointers contain what size structures // as well as further embedded pointers. // OS dependant: NA // Desc: A class designated to manage data in a bank or a queue. // // Required headers: // 1. Common.h == Contains common definitions & typedefs. //---------------------------------------------------------------------------- #ifndef __CBANK__ #define __CBANK__ #include "Common.h" //////////////////////////// // DEFS & TYPEDEFS // //////////////////////////// //Bank Size Type: Used to determine the size of the bank. //Currently a Word (16-bit) value can support a bank of 65534 packets. //Data range 0 & 65536 reserved for Bank Index Flags. typedef Word BST; //Bank Top & Tail flags must occuppy the last two values in the numeral range. #define BANK_INDEX_TOP 0xFFFF //2 ^ Sizeof(BST) #define BANK_INDEX_TAIL 0x0000 //0 -> Since the top is always the first element. typedef ECTYPE BANKERR; #define BK_OK EC_OK //Everything okay. #define BKERR_OUTOFMEM ECERR_OUTOFMEM //Out of Memory. #define BKERR_OUTOFRNG ECERR_OUTOFRNG //Index specified is out of range. #define BKERR_EMPTY ECERR_EMPTY //Bank is empty. #define BKERR_NULL ECERR_NULL //Value itself is null. #define BKERR_NA ECERR_NA //Function is not supported #define BKERR_NOTCREATE ECERR_NACREATE //The class was not created properly with the create function #define BKERR_DUP (0x01 + ECERR_BASECOUNT)//The message was a duplicate and was not created. #define BK_COUNT (0x02 + ECERR_BASECOUNT) //Classes built on top of the BK can use this to add custom errors. ////////////////////////// // PACKET STRUCTURE // ////////////////////////// typedef struct BANK_DATA_PACKET { Dword dwSize; void* pvData; BANK_DATA_PACKET* pNext; BANK_DATA_PACKET* pPrev; } BDP, *PBDP; class CBank { private: PBDP m_pTop_Packet; PBDP m_pTail_Packet; public: //Constructor & Destructor CBank(); ~CBank(); BST Depth(); /////////////////////////////////////////////////////////////////////////////////////////////////////// // Name: Exists // Date: 5/20/4 // Desc: Examines the void data type block of memory and size of to another in the bank. If a match // is made, true is returned else false is. // Parameters: // 1) void* pvData == A pointer to a void data type block of memory to match one in the bank. // 2) Dword dwSize == The size of the block of memory to check against in the bank. // 3) BST& rbstIndex == A reference that refers to a numeral location of the element found in the bank. ////////////////////////////////////////////////////////////////////////////////////////////////////// inline bool Exists(void* pvData, Dword dwSize, BST& rbstIndex){return Scan(pvData, dwSize, rbstIndex);} inline bool Exists(void* pvData, Dword dwSize){BST b;return Exists(pvData, dwSize, b);} /////////////////////////////////////////////////////////////////////////////////////////////////////// // Name: Exists // Desc: Examines the packet specified in the parameter and returns true if it exists. // Parameters: // 1) PBDP ppacket == Bank Data Pack that contains custom data that is checked to see // if it exists inside the bank. // 2) BST& rbstIndex == A reference that refers to a numeral location of the element found in the bank. // Return value: // bool == Returns true if the packet is found in the bank else returns false. ////////////////////////////////////////////////////////////////////////////////////////////////////// inline bool Exists(PBDP ppacket, BST& rbstIndex){return Scan(ppacket->pvData, ppacket->dwSize, rbstIndex);} inline bool Exists(PBDP ppacket){BST b;return Exists(ppacket, b);} BANKERR Pop(BST bstIndex=BANK_INDEX_TAIL); BANKERR Pop(void* hCallback, Dword dwSize); void Purge(); BANKERR Push(PBDP ppacket, BST bstIndex=BANK_INDEX_TOP); BANKERR Push(void* pvData, Dword dwSize, BST bstIndex=BANK_INDEX_TOP, PBDP* hAddress=NULL); BANKERR Replace(PBDP ppacket, BST bstIndex=BANK_INDEX_TOP); BANKERR Replace(void *pvData, Dword dwSize, BST bstIndex=BANK_INDEX_TOP); //PBDP Peek(BST bstIndex=BANK_INDEX_TOP); //PBDP Get(BST bstIndex=BANK_INDEX_TOP); PBDP Peek(BST bstIndex=BANK_INDEX_TAIL); PBDP Get(BST bstIndex=BANK_INDEX_TAIL); //Bank Manipulation BANKERR Swap(); BANKERR Rotate(BST bstIndex){return BKERR_NA;} private: inline bool IsEmpty(); void BankRepair(); bool Scan(void* pvData, Dword dwSize, BST& rbstIndex); BANKERR ReturnBankElement(PBDP* hCurrPacket, BST bstIndex); bool Compare(void* pvData1, void* pvData2, Dword dwSize); }; #endif